home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / os / 4.2bsd / osdep.h < prev    next >
Encoding:
C/C++ Source or Header  |  1989-08-04  |  5.7 KB  |  162 lines

  1. /***********************************************************
  2. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  3. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Digital or MIT not be
  12. used in advertising or publicity pertaining to distribution of the
  13. software without specific, written prior permission.  
  14.  
  15. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  18. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21. SOFTWARE.
  22.  
  23. ******************************************************************/
  24. /* $XConsortium: osdep.h,v 1.20 89/08/04 08:28:13 rws Exp $ */
  25.  
  26. #ifndef NULL
  27. #define NULL 0
  28. #endif
  29.  
  30. #define BOTIMEOUT 200 /* in milliseconds */
  31. #define BUFSIZE 4096
  32. #define BUFWATERMARK 8192
  33. #define MAXBUFSIZE (1 << 18)
  34. #if (NOFILE <= 128) /* 128 is value of MAXCLIENTS in dix layer */
  35. #define MAXSOCKS (NOFILE - 1)
  36. #else
  37. #define MAXSOCKS 128
  38. #endif
  39. #define mskcnt ((MAXSOCKS + 31) / 32)    /* size of bit array */
  40.  
  41. #if (mskcnt==1)
  42. #define BITMASK(i) (1 << (i))
  43. #define MASKIDX(i) 0
  44. #endif
  45. #if (mskcnt>1)
  46. #define BITMASK(i) (1 << ((i) & 31))
  47. #define MASKIDX(i) ((i) >> 5)
  48. #endif
  49.  
  50. #define MASKWORD(buf, i) buf[MASKIDX(i)]
  51. #define BITSET(buf, i) MASKWORD(buf, i) |= BITMASK(i)
  52. #define BITCLEAR(buf, i) MASKWORD(buf, i) &= ~BITMASK(i)
  53. #define GETBIT(buf, i) (MASKWORD(buf, i) & BITMASK(i))
  54.  
  55. #if (mskcnt==1)
  56. #define COPYBITS(src, dst) dst[0] = src[0]
  57. #define CLEARBITS(buf) buf[0] = 0
  58. #define MASKANDSETBITS(dst, b1, b2) dst[0] = (b1[0] & b2[0])
  59. #define ORBITS(dst, b1, b2) dst[0] = (b1[0] | b2[0])
  60. #define UNSETBITS(dst, b1) (dst[0] &= ~b1[0])
  61. #define ANYSET(src) (src[0])
  62. #endif
  63. #if (mskcnt==2)
  64. #define COPYBITS(src, dst) dst[0] = src[0]; dst[1] = src[1]
  65. #define CLEARBITS(buf) buf[0] = 0; buf[1] = 0
  66. #define MASKANDSETBITS(dst, b1, b2)  \
  67.               dst[0] = (b1[0] & b2[0]);\
  68.               dst[1] = (b1[1] & b2[1])
  69. #define ORBITS(dst, b1, b2)  \
  70.               dst[0] = (b1[0] | b2[0]);\
  71.               dst[1] = (b1[1] | b2[1])
  72. #define UNSETBITS(dst, b1) \
  73.                       dst[0] &= ~b1[0]; \
  74.                       dst[1] &= ~b1[1]
  75. #define ANYSET(src) (src[0] || src[1])
  76. #endif
  77. #if (mskcnt==3)
  78. #define COPYBITS(src, dst) dst[0] = src[0]; dst[1] = src[1]; dst[2] = src[2];
  79. #define CLEARBITS(buf) buf[0] = 0; buf[1] = 0; buf[2] = 0
  80. #define MASKANDSETBITS(dst, b1, b2)  \
  81.               dst[0] = (b1[0] & b2[0]);\
  82.               dst[1] = (b1[1] & b2[1]);\
  83.               dst[2] = (b1[2] & b2[2])
  84. #define ORBITS(dst, b1, b2)  \
  85.               dst[0] = (b1[0] | b2[0]);\
  86.               dst[1] = (b1[1] | b2[1]);\
  87.               dst[2] = (b1[2] | b2[2])
  88. #define UNSETBITS(dst, b1) \
  89.                       dst[0] &= ~b1[0]; \
  90.                       dst[1] &= ~b1[1]; \
  91.                       dst[2] &= ~b1[2]
  92. #define ANYSET(src) (src[0] || src[1] || src[2])
  93. #endif
  94. #if (mskcnt==4)
  95. #define COPYBITS(src, dst) dst[0] = src[0]; dst[1] = src[1]; dst[2] = src[2];\
  96.               dst[3] = src[3]
  97. #define CLEARBITS(buf) buf[0] = 0; buf[1] = 0; buf[2] = 0; buf[3] = 0
  98. #define MASKANDSETBITS(dst, b1, b2)  \
  99.                       dst[0] = (b1[0] & b2[0]);\
  100.                       dst[1] = (b1[1] & b2[1]);\
  101.                       dst[2] = (b1[2] & b2[2]);\
  102.                       dst[3] = (b1[3] & b2[3])
  103. #define ORBITS(dst, b1, b2)  \
  104.                       dst[0] = (b1[0] | b2[0]);\
  105.                       dst[1] = (b1[1] | b2[1]);\
  106.                       dst[2] = (b1[2] | b2[2]);\
  107.                       dst[3] = (b1[3] | b2[3])
  108. #define UNSETBITS(dst, b1) \
  109.                       dst[0] &= ~b1[0]; \
  110.                       dst[1] &= ~b1[1]; \
  111.                       dst[2] &= ~b1[2]; \
  112.                       dst[3] &= ~b1[3]
  113. #define ANYSET(src) (src[0] || src[1] || src[2] || src[3])
  114. #endif
  115.  
  116. #if (mskcnt>4)
  117. #define COPYBITS(src, dst) bcopy((caddr_t) src, (caddr_t) dst,\
  118.                  mskcnt*sizeof(long))
  119. #define CLEARBITS(buf) bzero((caddr_t) buf, mskcnt*sizeof(long))
  120. #define MASKANDSETBITS(dst, b1, b2)  \
  121.               { int cri;            \
  122.             for (cri=0; cri<mskcnt; cri++)    \
  123.                   dst[cri] = (b1[cri] & b2[cri]) }
  124. #define ORBITS(dst, b1, b2)  \
  125.               { int cri;            \
  126.               for (cri=0; cri<mskcnt; cri++)    \
  127.                   dst[cri] = (b1[cri] | b2[cri]) }
  128. #define UNSETBITS(dst, b1) \
  129.               { int cri;            \
  130.               for (cri=0; cri<mskcnt; cri++)    \
  131.                   dst[cri] &= ~b1[cri];  }
  132. /*
  133.  * If mskcnt>4, then ANYSET is a routine defined in WaitFor.c.
  134.  *
  135.  * #define ANYSET(src) (src[0] || src[1] || src[2] || src[3] || src[4] ...)
  136.  */
  137. #endif
  138.  
  139. typedef struct _connectionInput {
  140.     struct _connectionInput *next;
  141.     char *buffer;               /* contains current client input */
  142.     char *bufptr;               /* pointer to current start of data */
  143.     int  bufcnt;                /* count of bytes in buffer */
  144.     int lenLastReq;
  145.     int size;
  146. } ConnectionInput, *ConnectionInputPtr;
  147.  
  148. typedef struct _connectionOutput {
  149.     struct _connectionOutput *next;
  150.     int size;
  151.     unsigned char *buf;
  152.     int count;
  153. } ConnectionOutput, *ConnectionOutputPtr;
  154.  
  155. typedef struct _osComm {
  156.     int fd;
  157.     ConnectionInputPtr input;
  158.     ConnectionOutputPtr output;
  159.     XID    auth_id;        /* authorization id */
  160.     long conn_time;        /* timestamp if not established, else 0  */
  161. } OsCommRec, *OsCommPtr;
  162.